<?php
/**
 * 管理员
 * Created by Vscode.
 * User: Luanzg
 * Date: 2020/05/22 1526
 * Time: 15:26
 */
namespace app\common\validate;

use app\common\facade\model\AdminRoleModel;

class Roles extends BaseValidate
{

    /**
     * 姓名唯一
     * 自定义验证器
     */
    protected function nameUnique($value, $rule, $data)
    {

        $where[] = ['name', '=', $value];

        $info = AdminRoleModel::info($where, ['id']);

        if (!empty($info)) exception('角色名已存在');

        return true;
    }

    protected $field = [
        'name'      => '角色名',
        'description'  => '描述'

    ];

    protected $rule = [
        'name'       => 'require',
        'description'   => 'require'
    ];

    /**
     * 登录
     */
    protected function sceneaddsave()
    {
        return $this->only([
            'name',
        ]);
    }

}
